package com.etlmaster.executor.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式帮助类
 * 
 * @author Wugf
 * @date 2016-03-08
 */
public class Regex {
	public static boolean validation(String sql,String regex){
		Pattern p = Pattern.compile(regex);
	    Matcher m = p.matcher(sql);
	    if(m.find()){
	    	return true;
	    }else{
	    	return false;
	    }
		
	}
	public static String validation(String sql,String regex,int group){
		Pattern p = Pattern.compile(regex);
	    Matcher m = p.matcher(sql);
	    if(m.find()){
	    	return m.group(group);
	    }else{
	    	return "null";
	    }
		
	}
	public static String[] validations(String sql,String regex){
		Pattern p = Pattern.compile(regex);
	    Matcher m = p.matcher(sql);
	    if(m.find()){
	    	int length=m.groupCount();
	    	String []groups=new String[length];
	    	for(int i=0;i<length;i++){
	    		groups[i]=m.group(i+1);
	    	}
	    	return groups;
	    }else{
	    	return null;
	    }
		
	}
	

}
